import {createRouter, createWebHistory} from 'vue-router'
import routes from './routes'

const router= createRouter({
    history:createWebHistory(),
    routes
})

router.beforeEach((to, from, next) => {
    // @ts-ignore
    window.document.title=to.meta.title
    if(to.path==='/login'){
        window.localStorage.removeItem('token')
        next()
    }else{
        const token=window.localStorage.getItem('token')
        if(token){
            next()
        }else{
            window.localStorage.removeItem('token')
            next('/login')
        }
    }
})
export default router